8  Repeated-Measures ANOVA

Sample Problems

8.1 About

the repeated-measures ANOVA problems use the RamdomData class which requires:

  • an integer value for the number of groups
  • the sample size per group - all groups will have the same sample size
  • a call to the anova() method with test = "repeated-measures"

Each of the problems below sets factor levels using a random integer between 2 and 5. Per-group sample size is randomly set between 4 and 10. An example funciton call is included below

n_groups = random.randint(2,5)
sample_size = random.randint(4,10)
RandomData(groups = n_groups, n = sample_size).anova(test = "repeated-measures")

8.2 Problem 1

Given the following within-subjects data, use a repeated-measures ANOVA with \(\alpha = {0.05}\)

ID A B
1 36 31
2 28 29
3 28 38
4 34 43
5 35 35
6 22 43
7 44 37


Summary statistics for these data:
\(G = {483} \quad \Sigma X^2 = {17203} \quad k = {2} \quad N = {14}\)

\(T_{A} = {227} \quad SS_{A} = {303.71}\)
\(T_{B} = {256} \quad SS_{B} = {175.71}\)

State the Hypotheses
\(H_0: \mu_A = \mu_B\)
\(H_1:\) At least one mean is different

The decision criteria:

\(F_{crit} = {5.99}, \alpha = {0.05}\)

Stage 1 Calculations:

Calculate the Degrees of Freedom
\[df_{total} = N - 1\]
\[df_{total} = {14} - 1\]
\[df_{total} = {13}\]

\[df_{between} = k - 1\]
\[df_{between} = {2} - 1\]
\[df_{between} = {1}\]

\[df_{within} = N - K\]
\[df_{within} = {14} - {2}\]
\[df_{within} = {12}\]

Calculate the Sum of Squares
\[SS_{total} = \Sigma X^2 - \frac{G^2}{N}\]
\[SS_{total} = {17203} - \frac{483^2}{14}\]
\[SS_{total} = {17203} - \frac{233289}{14}\]
\[SS_{total} = {17203} - {16663.5}\]
\[SS_{total} = {539.5}\]

\[SS_{within} = \Sigma SS_{inside\_each\_condition}\]
\[SS_{within} = {303.71 + 175.71}\]
\[SS_{within} = {479.42}\]

\[SS_{between} = SS_{total} - SS_{within}\]
\[SS_{between} = {539.5} - {479.42}\]
\[SS_{between} = {60.08}\]

note: the other way to calculate \(SS_{betwen}\) is:
\[SS_{between} = \Sigma{\frac{T^2}{n}} - \frac{G^2}{N}\]

Stage 2 Calculations:

Partition the Degrees of Freedom
\[df_{subjects} = n - 1\]
\[df_{subjects} = {7} - 1\]
\[df_{subjects} = {6}\]

\[df_{error} = df_{within} - df_{subjects}\]
\[df_{error} = {12} - {6}\]
\[df_{error} = {6}\]

Calculate person sums and add a new column (P)

ID A B P
1 36 31 67
2 28 29 57
3 28 38 66
4 34 43 77
5 35 35 70
6 22 43 65
7 44 37 81

\[SS_{subjects} = \Sigma{\frac{P^2}{k}} - \frac{G^2}{N}\]
\[SS_{subjects} = {\frac{67^2}{2} + \frac{57^2}{2} + \frac{66^2}{2} + \frac{77^2}{2} + \frac{70^2}{2} + \frac{65^2}{2} + \frac{81^2}{2}} - \frac{483^2}{14}\]
\[SS_{subjects} = {\frac{4489}{2} + \frac{3249}{2} + \frac{4356}{2} + \frac{5929}{2} + \frac{4900}{2} + \frac{4225}{2} + \frac{6561}{2}} - \frac{233289}{14}\]
\[SS_{subjects} = {{2244.5} + {1624.5} + {2178.0} + {2964.5} + {2450.0} + {2112.5} + {3280.5}} - {16663.5}\]
\[SS_{subjects} = {16854.5} - {16663.5}\]
\[SS_{subjects} = {191.0}\]

\[SS_{error} = SS_{within} - SS_{subjects}\]
\[SS_{error} = {479.42} - {191.0}\]
\[SS_{error} = {288.42}\]

Calculate the Mean Squares
\[MS_{between} = \frac{SS_{between}}{df_{between}}\]
\[MS_{between} = \frac{60.08}{1}\]
\[MS_{between} = {60.08}\]

\[MS_{error} = \frac{SS_{error}}{df_{error}}\]
\[MS_{error} = \frac{288.42}{6}\]
\[MS_{error} = {48.07}\]

Calculate the F-Ratio
\[F_{obt} = \frac{MS_{between}}{MS_{error}}\]
\[F_{obt} = \frac{60.08}{48.07}\]
\[F_{obt} = {1.25}\]

Calculate \(\eta^2\)
\[\eta_p^2 = \frac{SS{between}}{SS_{total} - SS_{subjects}}\]
\[\eta_p^2 = \frac{60.08}{{539.5} - {191.0}}\]
\[\eta_p^2 = \frac{60.08}{348.5}\]
\[\eta_p^2 = {0.17}\]

The results:

fail to reject the null hypothesis, results not significant,

\(F({1}, {6}) = {1.25}, p > {0.05}, \eta_p^2 = {0.17}\)

8.3 Problem 2

Given the following within-subjects data, use a repeated-measures ANOVA with \(\alpha = {0.01}\)

ID A B C D
1 63 47 67 79
2 61 60 67 63
3 64 56 61 73
4 67 65 58 70
5 61 43 54 68
6 59 61 62 79


Summary statistics for these data:
\(G = {1508} \quad \Sigma X^2 = {96344} \quad k = {4} \quad N = {24}\)

\(T_{A} = {375} \quad SS_{A} = {39.5}\)
\(T_{B} = {332} \quad SS_{B} = {369.33}\)
\(T_{C} = {369} \quad SS_{C} = {129.5}\)
\(T_{D} = {432} \quad SS_{D} = {200.0}\)

State the Hypotheses
\(H_0: \mu_A = \mu_B = \mu_C = \mu_D\)
\(H_1:\) At least one mean is different

The decision criteria:

\(F_{crit} = {5.42}, \alpha = {0.01}\)

Stage 1 Calculations:

Calculate the Degrees of Freedom
\[df_{total} = N - 1\]
\[df_{total} = {24} - 1\]
\[df_{total} = {23}\]

\[df_{between} = k - 1\]
\[df_{between} = {4} - 1\]
\[df_{between} = {3}\]

\[df_{within} = N - K\]
\[df_{within} = {24} - {4}\]
\[df_{within} = {20}\]

Calculate the Sum of Squares
\[SS_{total} = \Sigma X^2 - \frac{G^2}{N}\]
\[SS_{total} = {96344} - \frac{1508^2}{24}\]
\[SS_{total} = {96344} - \frac{2274064}{24}\]
\[SS_{total} = {96344} - {94752.67}\]
\[SS_{total} = {1591.33}\]

\[SS_{within} = \Sigma SS_{inside\_each\_condition}\]
\[SS_{within} = {39.5 + 369.33 + 129.5 + 200.0}\]
\[SS_{within} = {738.33}\]

\[SS_{between} = SS_{total} - SS_{within}\]
\[SS_{between} = {1591.33} - {738.33}\]
\[SS_{between} = {853.0}\]

note: the other way to calculate \(SS_{betwen}\) is:
\[SS_{between} = \Sigma{\frac{T^2}{n}} - \frac{G^2}{N}\]

Stage 2 Calculations:

Partition the Degrees of Freedom
\[df_{subjects} = n - 1\]
\[df_{subjects} = {6} - 1\]
\[df_{subjects} = {5}\]

\[df_{error} = df_{within} - df_{subjects}\]
\[df_{error} = {20} - {5}\]
\[df_{error} = {15}\]

Calculate person sums and add a new column (P)

ID A B C D P
1 63 47 67 79 256
2 61 60 67 63 251
3 64 56 61 73 254
4 67 65 58 70 260
5 61 43 54 68 226
6 59 61 62 79 261

\[SS_{subjects} = \Sigma{\frac{P^2}{k}} - \frac{G^2}{N}\]
\[SS_{subjects} = {\frac{256^2}{4} + \frac{251^2}{4} + \frac{254^2}{4} + \frac{260^2}{4} + \frac{226^2}{4} + \frac{261^2}{4}} - \frac{1508^2}{24}\]
\[SS_{subjects} = {\frac{65536}{4} + \frac{63001}{4} + \frac{64516}{4} + \frac{67600}{4} + \frac{51076}{4} + \frac{68121}{4}} - \frac{2274064}{24}\]
\[SS_{subjects} = {{16384.0} + {15750.25} + {16129.0} + {16900.0} + {12769.0} + {17030.25}} - {94752.67}\]
\[SS_{subjects} = {94962.5} - {94752.67}\]
\[SS_{subjects} = {209.83}\]

\[SS_{error} = SS_{within} - SS_{subjects}\]
\[SS_{error} = {738.33} - {209.83}\]
\[SS_{error} = {528.5}\]

Calculate the Mean Squares
\[MS_{between} = \frac{SS_{between}}{df_{between}}\]
\[MS_{between} = \frac{853.0}{3}\]
\[MS_{between} = {284.33}\]

\[MS_{error} = \frac{SS_{error}}{df_{error}}\]
\[MS_{error} = \frac{528.5}{15}\]
\[MS_{error} = {35.23}\]

Calculate the F-Ratio
\[F_{obt} = \frac{MS_{between}}{MS_{error}}\]
\[F_{obt} = \frac{284.33}{35.23}\]
\[F_{obt} = {8.07}\]

Calculate \(\eta^2\)
\[\eta_p^2 = \frac{SS{between}}{SS_{total} - SS_{subjects}}\]
\[\eta_p^2 = \frac{853.0}{{1591.33} - {209.83}}\]
\[\eta_p^2 = \frac{853.0}{1381.5}\]
\[\eta_p^2 = {0.62}\]

The results:

reject the null hypothesis, results are significant,

\(F({3}, {15}) = {8.07}, p < {0.01}, \eta_p^2 = {0.62}\)

8.4 Problem 3

Given the following within-subjects data, use a repeated-measures ANOVA with \(\alpha = {0.05}\)

ID A B C D
1 39 41 42 30
2 41 43 47 36
3 50 39 47 40
4 41 48 53 38
5 51 37 49 46


Summary statistics for these data:
\(G = {858} \quad \Sigma X^2 = {37456} \quad k = {4} \quad N = {20}\)

\(T_{A} = {222} \quad SS_{A} = {127.2}\)
\(T_{B} = {208} \quad SS_{B} = {71.2}\)
\(T_{C} = {238} \quad SS_{C} = {63.2}\)
\(T_{D} = {190} \quad SS_{D} = {136.0}\)

State the Hypotheses
\(H_0: \mu_A = \mu_B = \mu_C = \mu_D\)
\(H_1:\) At least one mean is different

The decision criteria:

\(F_{crit} = {3.49}, \alpha = {0.05}\)

Stage 1 Calculations:

Calculate the Degrees of Freedom
\[df_{total} = N - 1\]
\[df_{total} = {20} - 1\]
\[df_{total} = {19}\]

\[df_{between} = k - 1\]
\[df_{between} = {4} - 1\]
\[df_{between} = {3}\]

\[df_{within} = N - K\]
\[df_{within} = {20} - {4}\]
\[df_{within} = {16}\]

Calculate the Sum of Squares
\[SS_{total} = \Sigma X^2 - \frac{G^2}{N}\]
\[SS_{total} = {37456} - \frac{858^2}{20}\]
\[SS_{total} = {37456} - \frac{736164}{20}\]
\[SS_{total} = {37456} - {36808.2}\]
\[SS_{total} = {647.8}\]

\[SS_{within} = \Sigma SS_{inside\_each\_condition}\]
\[SS_{within} = {127.2 + 71.2 + 63.2 + 136.0}\]
\[SS_{within} = {397.6}\]

\[SS_{between} = SS_{total} - SS_{within}\]
\[SS_{between} = {647.8} - {397.6}\]
\[SS_{between} = {250.2}\]

note: the other way to calculate \(SS_{betwen}\) is:
\[SS_{between} = \Sigma{\frac{T^2}{n}} - \frac{G^2}{N}\]

Stage 2 Calculations:

Partition the Degrees of Freedom
\[df_{subjects} = n - 1\]
\[df_{subjects} = {5} - 1\]
\[df_{subjects} = {4}\]

\[df_{error} = df_{within} - df_{subjects}\]
\[df_{error} = {16} - {4}\]
\[df_{error} = {12}\]

Calculate person sums and add a new column (P)

ID A B C D P
1 39 41 42 30 152
2 41 43 47 36 167
3 50 39 47 40 176
4 41 48 53 38 180
5 51 37 49 46 183

\[SS_{subjects} = \Sigma{\frac{P^2}{k}} - \frac{G^2}{N}\]
\[SS_{subjects} = {\frac{152^2}{4} + \frac{167^2}{4} + \frac{176^2}{4} + \frac{180^2}{4} + \frac{183^2}{4}} - \frac{858^2}{20}\]
\[SS_{subjects} = {\frac{23104}{4} + \frac{27889}{4} + \frac{30976}{4} + \frac{32400}{4} + \frac{33489}{4}} - \frac{736164}{20}\]
\[SS_{subjects} = {{5776.0} + {6972.25} + {7744.0} + {8100.0} + {8372.25}} - {36808.2}\]
\[SS_{subjects} = {36964.5} - {36808.2}\]
\[SS_{subjects} = {156.3}\]

\[SS_{error} = SS_{within} - SS_{subjects}\]
\[SS_{error} = {397.6} - {156.3}\]
\[SS_{error} = {241.3}\]

Calculate the Mean Squares
\[MS_{between} = \frac{SS_{between}}{df_{between}}\]
\[MS_{between} = \frac{250.2}{3}\]
\[MS_{between} = {83.4}\]

\[MS_{error} = \frac{SS_{error}}{df_{error}}\]
\[MS_{error} = \frac{241.3}{12}\]
\[MS_{error} = {20.11}\]

Calculate the F-Ratio
\[F_{obt} = \frac{MS_{between}}{MS_{error}}\]
\[F_{obt} = \frac{83.4}{20.11}\]
\[F_{obt} = {4.15}\]

Calculate \(\eta^2\)
\[\eta_p^2 = \frac{SS{between}}{SS_{total} - SS_{subjects}}\]
\[\eta_p^2 = \frac{250.2}{{647.8} - {156.3}}\]
\[\eta_p^2 = \frac{250.2}{491.5}\]
\[\eta_p^2 = {0.51}\]

The results:

reject the null hypothesis, results are significant,

\(F({3}, {12}) = {4.15}, p < {0.05}, \eta_p^2 = {0.51}\)

8.5 Problem 4

Given the following within-subjects data, use a repeated-measures ANOVA with \(\alpha = {0.05}\)

ID A B
1 14 32
2 29 37
3 18 31
4 20 39
5 30 30
6 21 29


Summary statistics for these data:
\(G = {330} \quad \Sigma X^2 = {9718} \quad k = {2} \quad N = {12}\)

\(T_{A} = {132} \quad SS_{A} = {198.0}\)
\(T_{B} = {198} \quad SS_{B} = {82.0}\)

State the Hypotheses
\(H_0: \mu_A = \mu_B\)
\(H_1:\) At least one mean is different

The decision criteria:

\(F_{crit} = {6.61}, \alpha = {0.05}\)

Stage 1 Calculations:

Calculate the Degrees of Freedom
\[df_{total} = N - 1\]
\[df_{total} = {12} - 1\]
\[df_{total} = {11}\]

\[df_{between} = k - 1\]
\[df_{between} = {2} - 1\]
\[df_{between} = {1}\]

\[df_{within} = N - K\]
\[df_{within} = {12} - {2}\]
\[df_{within} = {10}\]

Calculate the Sum of Squares
\[SS_{total} = \Sigma X^2 - \frac{G^2}{N}\]
\[SS_{total} = {9718} - \frac{330^2}{12}\]
\[SS_{total} = {9718} - \frac{108900}{12}\]
\[SS_{total} = {9718} - {9075.0}\]
\[SS_{total} = {643.0}\]

\[SS_{within} = \Sigma SS_{inside\_each\_condition}\]
\[SS_{within} = {198.0 + 82.0}\]
\[SS_{within} = {280.0}\]

\[SS_{between} = SS_{total} - SS_{within}\]
\[SS_{between} = {643.0} - {280.0}\]
\[SS_{between} = {363.0}\]

note: the other way to calculate \(SS_{betwen}\) is:
\[SS_{between} = \Sigma{\frac{T^2}{n}} - \frac{G^2}{N}\]

Stage 2 Calculations:

Partition the Degrees of Freedom
\[df_{subjects} = n - 1\]
\[df_{subjects} = {6} - 1\]
\[df_{subjects} = {5}\]

\[df_{error} = df_{within} - df_{subjects}\]
\[df_{error} = {10} - {5}\]
\[df_{error} = {5}\]

Calculate person sums and add a new column (P)

ID A B P
1 14 32 46
2 29 37 66
3 18 31 49
4 20 39 59
5 30 30 60
6 21 29 50

\[SS_{subjects} = \Sigma{\frac{P^2}{k}} - \frac{G^2}{N}\]
\[SS_{subjects} = {\frac{46^2}{2} + \frac{66^2}{2} + \frac{49^2}{2} + \frac{59^2}{2} + \frac{60^2}{2} + \frac{50^2}{2}} - \frac{330^2}{12}\]
\[SS_{subjects} = {\frac{2116}{2} + \frac{4356}{2} + \frac{2401}{2} + \frac{3481}{2} + \frac{3600}{2} + \frac{2500}{2}} - \frac{108900}{12}\]
\[SS_{subjects} = {{1058.0} + {2178.0} + {1200.5} + {1740.5} + {1800.0} + {1250.0}} - {9075.0}\]
\[SS_{subjects} = {9227.0} - {9075.0}\]
\[SS_{subjects} = {152.0}\]

\[SS_{error} = SS_{within} - SS_{subjects}\]
\[SS_{error} = {280.0} - {152.0}\]
\[SS_{error} = {128.0}\]

Calculate the Mean Squares
\[MS_{between} = \frac{SS_{between}}{df_{between}}\]
\[MS_{between} = \frac{363.0}{1}\]
\[MS_{between} = {363.0}\]

\[MS_{error} = \frac{SS_{error}}{df_{error}}\]
\[MS_{error} = \frac{128.0}{5}\]
\[MS_{error} = {25.6}\]

Calculate the F-Ratio
\[F_{obt} = \frac{MS_{between}}{MS_{error}}\]
\[F_{obt} = \frac{363.0}{25.6}\]
\[F_{obt} = {14.18}\]

Calculate \(\eta^2\)
\[\eta_p^2 = \frac{SS{between}}{SS_{total} - SS_{subjects}}\]
\[\eta_p^2 = \frac{363.0}{{643.0} - {152.0}}\]
\[\eta_p^2 = \frac{363.0}{491.0}\]
\[\eta_p^2 = {0.74}\]

The results:

reject the null hypothesis, results are significant,

\(F({1}, {5}) = {14.18}, p < {0.05}, \eta_p^2 = {0.74}\)

8.6 Problem 5

Given the following within-subjects data, use a repeated-measures ANOVA with \(\alpha = {0.01}\)

ID A B
1 49 48
2 60 47
3 65 49
4 60 37
5 60 39
6 51 43


Summary statistics for these data:
\(G = {608} \quad \Sigma X^2 = {31680} \quad k = {2} \quad N = {12}\)

\(T_{A} = {345} \quad SS_{A} = {189.5}\)
\(T_{B} = {263} \quad SS_{B} = {124.83}\)

State the Hypotheses
\(H_0: \mu_A = \mu_B\)
\(H_1:\) At least one mean is different

The decision criteria:

\(F_{crit} = {16.26}, \alpha = {0.01}\)

Stage 1 Calculations:

Calculate the Degrees of Freedom
\[df_{total} = N - 1\]
\[df_{total} = {12} - 1\]
\[df_{total} = {11}\]

\[df_{between} = k - 1\]
\[df_{between} = {2} - 1\]
\[df_{between} = {1}\]

\[df_{within} = N - K\]
\[df_{within} = {12} - {2}\]
\[df_{within} = {10}\]

Calculate the Sum of Squares
\[SS_{total} = \Sigma X^2 - \frac{G^2}{N}\]
\[SS_{total} = {31680} - \frac{608^2}{12}\]
\[SS_{total} = {31680} - \frac{369664}{12}\]
\[SS_{total} = {31680} - {30805.33}\]
\[SS_{total} = {874.67}\]

\[SS_{within} = \Sigma SS_{inside\_each\_condition}\]
\[SS_{within} = {189.5 + 124.83}\]
\[SS_{within} = {314.33}\]

\[SS_{between} = SS_{total} - SS_{within}\]
\[SS_{between} = {874.67} - {314.33}\]
\[SS_{between} = {560.34}\]

note: the other way to calculate \(SS_{betwen}\) is:
\[SS_{between} = \Sigma{\frac{T^2}{n}} - \frac{G^2}{N}\]

Stage 2 Calculations:

Partition the Degrees of Freedom
\[df_{subjects} = n - 1\]
\[df_{subjects} = {6} - 1\]
\[df_{subjects} = {5}\]

\[df_{error} = df_{within} - df_{subjects}\]
\[df_{error} = {10} - {5}\]
\[df_{error} = {5}\]

Calculate person sums and add a new column (P)

ID A B P
1 49 48 97
2 60 47 107
3 65 49 114
4 60 37 97
5 60 39 99
6 51 43 94

\[SS_{subjects} = \Sigma{\frac{P^2}{k}} - \frac{G^2}{N}\]
\[SS_{subjects} = {\frac{97^2}{2} + \frac{107^2}{2} + \frac{114^2}{2} + \frac{97^2}{2} + \frac{99^2}{2} + \frac{94^2}{2}} - \frac{608^2}{12}\]
\[SS_{subjects} = {\frac{9409}{2} + \frac{11449}{2} + \frac{12996}{2} + \frac{9409}{2} + \frac{9801}{2} + \frac{8836}{2}} - \frac{369664}{12}\]
\[SS_{subjects} = {{4704.5} + {5724.5} + {6498.0} + {4704.5} + {4900.5} + {4418.0}} - {30805.33}\]
\[SS_{subjects} = {30950.0} - {30805.33}\]
\[SS_{subjects} = {144.67}\]

\[SS_{error} = SS_{within} - SS_{subjects}\]
\[SS_{error} = {314.33} - {144.67}\]
\[SS_{error} = {169.66}\]

Calculate the Mean Squares
\[MS_{between} = \frac{SS_{between}}{df_{between}}\]
\[MS_{between} = \frac{560.34}{1}\]
\[MS_{between} = {560.34}\]

\[MS_{error} = \frac{SS_{error}}{df_{error}}\]
\[MS_{error} = \frac{169.66}{5}\]
\[MS_{error} = {33.93}\]

Calculate the F-Ratio
\[F_{obt} = \frac{MS_{between}}{MS_{error}}\]
\[F_{obt} = \frac{560.34}{33.93}\]
\[F_{obt} = {16.51}\]

Calculate \(\eta^2\)
\[\eta_p^2 = \frac{SS{between}}{SS_{total} - SS_{subjects}}\]
\[\eta_p^2 = \frac{560.34}{{874.67} - {144.67}}\]
\[\eta_p^2 = \frac{560.34}{730.0}\]
\[\eta_p^2 = {0.77}\]

The results:

reject the null hypothesis, results are significant,

\(F({1}, {5}) = {16.51}, p < {0.01}, \eta_p^2 = {0.77}\)